<%@ page language="java" import="java.util.*" pageEncoding="utf-8" %>
<%@include file="/commons/taglibs.jsp" %>
<!DOCTYPE html>
<html >
<fmt:bundle basename="res">
<head>
    <meta charset="utf-8">
    <title><fmt:message key='ttbl' /></title>
    <jsp:include page="/WEB-INF/commons/commons-header.jsp" flush="true"/>
    <style>
        html {background:#fff;}
    </style>
</head>

<body >
<div class="layui-container">
<div class="layui-form" lay-filter="layuiadmin-app-form-list" id="layuiadmin-app-form-list" style="padding: 20px 30px 0 0;">

    <form:form commandName="brand" method="${_method }" class="layui-form" id="form">
        <input type="hidden" name="_method" value="${_method }"/>
        <form:hidden path="id"/>
        <div class="layui-form-item">
            <label class="layui-form-label"><b style="color:red">*</b> <fmt:message key='ppmc' /></label>
            <div class="layui-input-block">
                <form:input path="name" class="layui-input" placeholder="品牌名称" style="width: 300px;"/>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label"><b style="color:red">*</b> <fmt:message key='pplg' /></label>
            <div class="layui-input-inline" style="width: 70%;">
                <form:hidden path="logo" lay-verify="required"/>
                <a type="button" id="chooseImage" class="layui-btn layui-btn-sm layui-btn-normal"><fmt:message key='sctp' /></a>
                <div id="imageBox">
                    <c:if test="${not empty brand.logo}">
                        <img class="preview" src="${store_domain}/uploads/${brand.logo}" style="width:120px;height:120px;margin-top:10px;">
                    </c:if>
                    <c:if test="${empty brand.logo}">
                        <img src="${web_domain}/resources/images/default.jpeg" style="width:120px;height:120px;margin-top:10px;">
                    </c:if>
                </div>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label"><fmt:message key='bz' /></label>
            <div class="layui-input-block">
                <form:textarea path="note" class="layui-input" placeholder="<fmt:message key='bz' />" style="width: 300px;height:200px;" />
            </div>
        </div>

        <div class="layui-input-block">
            <div style="display: none"><input type="button" value="<fmt:message key='bc' />" class="layui-btn" id="submit" lay-filter="submit" lay-submit></div>
        </div>

    </form:form>
</div>
</div>

<div style="display: none;">
    <form action="${web_domain}/upload/image" method="post" id="uploadImage" enctype="multipart/form-data">
        <input id="uploadImageFile" name="file" type="file" accept="image/*"/>
    </form>
</div>

<script>
    $(function () {

        layui.use(['form', 'laydate'], function () {

            var form = layui.form;
            var laydate = layui.laydate;

            $("#chooseImage").click(function () {
                $("#uploadImageFile").click();
            });

            $("#uploadImageFile").change(function () {
                $("#uploadImage").ajaxSubmit({
                    dataType: "JSON",
                    success: function (result) {
                        if (result.status) {
                            $("#logo").attr("value", result.path);
                            $("#imageBox").html("<img class='preview' src='${store_domain}/uploads/" + result.path + "' style='width:120px;height:120px;margin-top:10px;' />'");
                        }
                    },
                    error: function (result) {
                        console.log(result.responseText);
                    }
                });
            });


            form.on('submit(submit)', function (data) {

                $("#form").ajaxSubmit({
                    success: function (result) {
                        if (result.status) {
                            var index = parent.layer.getFrameIndex(window.name);
                            parent.layer.close(index);
                            parent.$("#search").click();
                        } else {
                            layui.use('layer', function () {
                                layer.msg(result.message);
                            });
                        }
                    }
                });
            });

        });

    });
</script>
</body>
</fmt:bundle>
</html>